package com.laivi.basic.model.datastruct;

import java.util.HashMap;
import java.util.Map;

/**
 * @copyright www.mvs.com.cn
 * @author zhuwei3@mvs.com.cn
 *
 * description:构造查询字段封装
 */
@SuppressWarnings("serial")
public class ValueMap extends HashMap<String, Object> {
	
	public synchronized static ValueMap createMap(){
		return new ValueMap();
	}
	
	public ValueMap add(String field,Object value){
		this.put(field, value);
		return this;
	}
	
	public String toString(boolean hasHead){
		StringBuffer sb=new StringBuffer();
		StringBuffer head=new StringBuffer();
		for(Map.Entry<String, Object> entry:this.entrySet()){
			if(hasHead){
				head.append(entry.getKey()+"\t");
			}
			sb.append(entry.getValue()+"\t");
		}
		head.append("\n"+sb.toString());
		return head.toString();
	}
	
	/**
	 * 获取ValueMap中的所有字段
	 * @return 字段数组
	 */
	public String[] getKeys(){
		String[] fields=new String[this.size()];
		int i=0;
		for(Map.Entry<String, Object>entry:this.entrySet()){
			fields[i++]=entry.getKey();
		}
		return fields;
	}
	
}
